<?php
// for 订餐
// by wcj
// @2017.2.15
class FoodAction extends CommAction{
	//订餐首页
	public function index(){
		$info1 = M('order_food_kind')->where(array('online'=>1))->select();
		$programNname = explode('/',$_SERVER['REDIRECT_URL']);
		foreach($info1 as $k=>$val){
			$info[$k]['id'] = $val['id'];
			$info[$k]['name'] = $val['name'];
			$info[$k]['logo'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$programNname[1].'/upload/food/'.$val['logo'];
		}
		$this->assign('info',$info);
		$this->display();
	}
	//餐品套餐列表
	public function Package(){
		$kindid = I('get.kindid');
		//当前选中的餐品分类名称
		$kindName = M('order_food_kind')->where(array('id'=>$kindid))->getField('name');
		$this->assign('kindName',$kindName);
		$info1 = M('order_food_detail')->where(array('kindid'=>$kindid))->select();
		$programNname = explode('/',$_SERVER['REDIRECT_URL']);
		foreach($info1 as $k=>$val){
			$info[$k]['id'] = $val['id'];
			$info[$k]['kindid'] = $val['kindid'];
			$info[$k]['name'] = $val['name'];
			$info[$k]['logo'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$programNname[1].'/upload/food/'.$val['logo'];
			$info[$k]['total_num'] = $val['total_num'];
			$info[$k]['rest'] = $val['rest'];
			$info[$k]['price'] = $val['price'];
		}
		$this->assign('info',$info);
		//选择分类
		$kinds = M('order_food_kind')->where(array('online'=>1))->select();
		$this->assign('kinds',$kinds);
		$this->display();
	}
	//套餐详情
	public function foodDetail(){
		$foodid = I('get.foodid');
		$info = M('order_food_detail')->where(array('id'=>$foodid))->find();
		$arr = array(
			$info['extra'],$info['extra1'],$info['extra2'],$info['extra3'],$info['extra4']
			);
		$maxi=array_search(max($arr),$arr);
		$max = $arr[$maxi] + $info['price'];
		$max = sprintf("%.2f", $max);
		$this->assign('info',$info);
		$this->assign('max',$max);
		$this->display();
	}
	//动态获取餐品规格
	public function getNormsByAjax(){
		if(IS_AJAX){
			$foodid = I('get.foodid');
			$norms = trim(I('get.norms'));
			$info = M('order_food_detail')->where(array('id'=>$foodid))->find();
			if($norms == $info['norms']){
				$extra = $info['extra'];
			}
			if($norms == $info['norms1']){
				$extra = $info['extra1'];
			}
			if($norms == $info['norms2']){
				$extra = $info['extra2'];
			}
			if($norms == $info['norms3']){
				$extra = $info['extra3'];
			}
			if($norms == $info['norms4']){
				$extra = $info['extra4'];
			}
			$this->ajaxReturn(array('val'=>$extra,'perPrice'=>$info['price']));

		}
	}
	



	
}